package org.me.client;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.ScrollListener;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SourcesTableEvents;
import com.google.gwt.user.client.ui.TableListener;
import com.google.gwt.user.client.ui.Widget;

public class Datenrasterfeld extends Composite implements ClickListener,ScrollListener {
	static final int MAX_N=16;
	static final int MAX_M=20;
	private Object[][] A;
	private Grid rasterfeld;
	private ScrollPanel panel;

	public Datenrasterfeld() {
		super();
		this.rasterfeld=new Grid(MAX_M,MAX_N);
		this.A=new Object[MAX_M][MAX_N];
		for (int i = 0; i < rasterfeld.getRowCount(); i++) {
			for (int j = 0; j < rasterfeld.getColumnCount(); j++) {
				rasterfeld.setHTML(i, j, A[i][j].toString());
				rasterfeld.addTableListener(new TableListener() {
					public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
						//TODO:pop up textbox

					}
				});
			}
		}
		panel.add(rasterfeld);
		initWidget(panel);
	}

	public Datenrasterfeld(Object[][] A,int M,int N){
		if(M<=MAX_M&&N<=MAX_N){
			this.rasterfeld=new Grid(N,M);
		}else{
			this.rasterfeld=new Grid(MAX_M,MAX_N);
		}
		for (int i = 0; i < rasterfeld.getRowCount(); i++) {
			for (int j = 0; j < rasterfeld.getColumnCount(); j++) {
				rasterfeld.setHTML(i, j, A[i][j].toString());
			}
		}
	}

	public void onClick(Widget sender) {


	}

	public void onScroll(Widget widget, int scrollLeft, int scrollTop) {
		// TODO Auto-generated method stub

	}

}
